package cn.com.ustudy.course.core.model.vo;

import cn.com.ustudy.course.core.model.entity.Course;
import cn.com.ustudy.course.core.model.entity.CourseCatalog;
import cn.com.ustudy.course.core.model.enums.CourseType;
import cn.melonlib.cores.commons.model.entity.TenantRecordEntity;
import cn.melonlib.cores.model.anno.ModelComment;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;

@Data
@EqualsAndHashCode(callSuper = true)
@ModelComment("课程信息")
public class CourseVo extends TenantRecordEntity {

    public CourseVo(Course course) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        BeanUtils.copyProperties(course, this);
        if (this.courseCatalog != null) {
            this.courseCatalogName = courseCatalog.getName();
            this.courseCatalogId = courseCatalog.getId();
        }
//        this.setSectionsTree(objectMapper.readValue(course.getSections(), new TypeReference<List<CourseSection>>() {
//        }));
    }

    @ModelComment(value = "课程分类", required = true)
    private CourseCatalog courseCatalog;

    @ModelComment("课程分类名称")
    private String courseCatalogName;

    @ModelComment("课程类目ID")
    private String courseCatalogId;

    @ModelComment(value = "课程名称", required = true)
    private String name;

    @ModelComment("封面图")
    private String logo;

    @ModelComment("授课教师")
    private String teacherName;

    @ModelComment("学分")
    private Double credit;


    @ModelComment("课程介绍")
    private String summary;

    @ModelComment("课程课件，章节树信息")
    private String sections;

//    @ModelComment("课程课件，章节树信息")
//    private List<CourseSection> sectionsTree;

    @ModelComment("开放学习")
    private Boolean pub = true;

    @ModelComment("总时长")
    private Long totalTime = 0L;

    @ModelComment("点击量")
    private Long clickNum = 0L;

    @ModelComment("学习人数")
    public Long studyNum = 0L;

    @ModelComment("上线")
    private Boolean online = true;

    @ModelComment("课程类型")
    @Enumerated(EnumType.STRING)
    private CourseType courseType = CourseType.ONLINE;

    @ModelComment("课程介绍")
    private String memo;
}
